package main

import "fmt"

func main() {
	// var heroes = make(map[string]string, 2)
	// heroes["no1"] = "光能使者"
	// heroes["no2"] = "风暴使者"
	// heroes["no3"] = "波涛使者"
	// fmt.Println(heroes)

	// cities := make(map[string]string, 2)
	// cities["no1"] = "苏州"
	// cities["no2"] = "北京"
	// cities["no3"] = "南京"
	// fmt.Println(cities)

	//test nest map
	// studentMap := make(map[string]map[string]string)
	// studentMap["stu01"] = make(map[string]string)
	// studentMap["stu01"]["name"] = "vincent"
	// studentMap["stu01"]["sex"] = "male"
	// studentMap["stu01"]["address"] = "上海南京路"

	// studentMap["stu02"] = make(map[string]string)
	// studentMap["stu02"]["name"] = "sara"
	// studentMap["stu02"]["sex"] = "female"
	// studentMap["stu02"]["address"] = "苏州观前街"

	// fmt.Println(studentMap)
	// fmt.Println(studentMap["stu02"])
	// fmt.Println(studentMap["stu02"]["address"])

	//test map's add and upd, key 存在的话就修改 key不存在则新增
	cities := make(map[string]string, 2)
	cities["no1"] = "苏州"
	cities["no2"] = "北京"
	cities["no3"] = "南京"
	// fmt.Println(cities)
	cities["no3"] = "无锡"
	// fmt.Println(cities)
	cities["no4"] = "常州"
	fmt.Println(cities)
	// delete(cities, "no5")
	// fmt.Println(cities)
	// delete(cities, "no4")
	// fmt.Println(cities)
	//删除所有的元素 直接可以make一个新的map 让原来的成为垃圾 被gc回收
	// cities = make(map[string]string)
	// fmt.Println(cities)

	//map查找
	city, ok := cities["no5"]
	if ok {
		fmt.Printf("该key的值为%v\n", city)
	} else {
		fmt.Println("没有这个key")
	}
}
